﻿using Microsoft.AspNetCore.Http;
using Models.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using UtilsORM;
using UtilsORM.MySqlData;

////using System.Web.Script.Serialization;

namespace GatewayServerService.Data
{
    public class DBIotDeviceTaskPlain
    {


        EFYihongIotContext ef = new EFYihongIotContext();
        public iot_device_task_plain getPlain(string guid)
        {
            return ef.iot_device_task_plain.Where(c => c.tp_guid == guid).FirstOrDefault();
        }

        public List<iot_device_task_plain> getPlainList(string cguid)
        {
            return ef.iot_device_task_plain.Where(c => c.tp_status == 0 && c.tp_c_guid == cguid).ToList();
        }
        public bool saveAll(IFormCollection FC, HttpReqModel httpRequest, MagerLoginInfo LoginUserInfo, iot_device_task_plain req)
        {

            //先查一下有没重复提交
            iot_device_task_plain model = ef.iot_device_task_plain.Where(c => c.tp_guid == req.tp_guid).FirstOrDefault();
            if (model == null)
            {

                //写入
                req.tp_add_time = DateTime.Now;
                req.tp_mod_time = DateTime.Now;
                req.tp_complete = 1;
                ef.iot_device_task_plain.Add(req);
                ef.SaveChanges();
            }
            else
            {

                model.tp_title = req.tp_title;
                model.tp_mod_time = DateTime.Now;
                ef.iot_device_task_plain.Update(model);
                ef.SaveChanges();
            }

            return true;
        }

    }
}
